<!--追加评价-->
<template>
	<div class="a">
		<van-nav-bar
		  title="追加评论"
		  left-arrow
		  @click-left="onClickLeft"
		  :border="false"
		>	
		  <van-icon name="arrow-left" slot="left" color="#000" size="20"/>
	    </van-nav-bar>	
		<van-field 
		  v-model="params.commentTxt"
		  rows="3"
		  autosize
		  label-width='0'
		  type="textarea"
		  placeholder="聊聊这次交易您的感受"		  
		/> 
		<div class="b">
			<van-uploader v-model="fileList"   :max-count="3"
				:after-read="afterRead" :before-delete="deleteImg">
				<img src="../../../../../static/img/shangchuan.png" alt="" />
			</van-uploader>
		</div>

		
		
		<div class="d">
			<div class="d1">
				<van-button color="#ffda44" block class="d2" @click="publish">发表评论</van-button>
			</div>
		</div>
  
	</div>	
</template>

<script>

import {getFun,getTimer} from '@/api/publicFun.js'	 
let publicFun=getFun()		
export default {
	name: 'appendEvaluate',	
	data() {
       return {
          params:{
          	commentTxt:'',
          	goodsId:'',
          	ordersId:'',
          	userId:'',
          	commentIsgood:0,
          	commentImage:''
          },
          url1:'/oss/api/v1/market/upload/common', // 用于绑定图片上传地址
          fileList:[],
          url2:this.$api+'/marketorderservice/api/v1/market/addCommnet',
          commentImage:[] // 储存上传图片          
       }
	},
	methods: {	
		// base64转图片
		dataURLtoBlob(dataurl) {		
		    var arr = dataurl.split(','),		
		    mime = arr[0].match(/:(.*?);/)[1],		
		    bstr = atob(arr[1]),		
		    n = bstr.length,		
		    u8arr = new Uint8Array(n);		
		    while (n--) {		
		        u8arr[n] = bstr.charCodeAt(n);		
		    }		
		    return new Blob([u8arr], {		
		        type: mime		
		    });		
		},
		// 保存服务器图片路径
		afterRead(res){	
			let that=this
	        var obj = this.dataURLtoBlob(res.content);
			var fd = new FormData();
			fd.append("file", obj,"image.png");
			this.$jquery.ajax({
			    url: this.url1,
			    type: "POST",
			    processData: false,
			    contentType: false,
			    data: fd,
			    success: function (result) {
			    	that.commentImage.push(result.data.url)			    	
			    }
			});		
		},
		deleteImg(file,detail){
            let index=detail.index
            // 删除图片
            this.commentImage.splice(index,1);
            this.fileList.splice(index,1);
		},
		publish(){			
			this.params.commentImage=this.commentImage.join(',')
			let that=this
		    this.$Axios.Post(this.url2,this.params)
		      .then(function(res) {
		      	  let arg='[{"ordersId":"'+that.params.ordersId+'"},{"comId":"'+that.params.goodsId+'"}]' 
				  that.link('/market/order/lookEvaluate',arg)	  
		    }) 			
			
		}
	},
	mixins:[publicFun],//混入		
	mounted() {
		this.params.ordersId=this.$router.currentRoute.query.ordersId;
		this.params.userId=this.$router.currentRoute.query.userId;	
		this.params.goodsId=this.$router.currentRoute.query.comId
	}
}	
</script>

<style scoped="">
.a{background: #e5e5e5;height: 100%;width: 100%;position: absolute;}
.d{position: absolute;bottom: 0;left: 0;width: 100%;background: #fff;padding: 10px;}
.van-button__text{color: #000;font-size: 16px;}


.b{padding: 10px 15px;background: #fff;}
</style>